﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using EntityManage;
using BusinessFacade;

public partial class Modules_Default_MyMessage : System.Web.UI.Page
{
    ISys_UserHandler userHandler = new Sys_UserManage();
    ISys_OrganizationHandler orgHandler = new Sys_OrganizationManage();
    IOther_MessageHandler msgHandler = new Other_MessageManage();
    IOther_MessageReceverHandler msgRecvHandler = new Other_MessageReceverManage();
    IOther_MessageHandlerExt msgExtHandler = new Other_MessageManageExt();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["OrderBy"] = "Id";
            ViewState["Accending"] = "desc";

            dataBind(" 1=1 ", new SqlParameter[]{});
          
        }
    }

    /// <summary>
    /// 初始化岗位信息表
    /// </summary>
    private void dataBind(string whereClause, SqlParameter[] parms)
    {
        try
        {
            whereClause += " and User_ID = " + Session["CurrentUserID"].ToString();
            DataTable dt = msgHandler.GetOther_MessageList(whereClause, parms, " ID desc");
            gvMessageList.DataSource = dt;
            gvMessageList.DataBind();
        }
        catch
        {
            Jscript.AlertInAjax("連接錯誤!", UpdatePanel1);
            return;
        }
    }

    protected void gvMessageList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex > -1)
            {
                string recv = "";
                Other_MessageReceverQuery[] recvQuery = msgRecvHandler.GetOther_MessageReceverQueryList(" Message_ID=" + e.Row.Cells[4].Text, null);
                if (recvQuery != null && recvQuery.Length > 0)
                {
                    foreach (Other_MessageReceverQuery query in recvQuery)
                    {
                        Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(query.User_ID);
                        if (userQuery != null)
                            recv = recv + userQuery.Name + ",";
                    }

                    recv = recv.Substring(0, recv.Length - 1);
                }
                e.Row.Cells[4].Text = recv;
            }
        }
    }

    protected void gvMessageList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //
        if (e.CommandName == "view")
        {
            int id = Convert.ToInt32(e.CommandArgument.ToString().Trim());
            try
            {
                
            }
            catch
            {
                Jscript.AlertInAjax("操作失败!", UpdatePanel1);
            }
        }
    }

    protected void CreateButton_Click(object sender, EventArgs e)
    {
        dataBind(" 1=1 ", new SqlParameter[] { });
    }

}
